import { MyVue } from 'src/wl/my_vue';
import Vue from 'vue';
import { Component, Emit, Prop, Provide, Watch } from 'vue-property-decorator'
import { MemberConst } from "src/consts/member_const";
@Component({})
export default class MemberSetPanel extends MyVue {
    name: string = 'MemberPanel';
    authority_list: any
    formData: any;
    footerFlag: boolean = true;
    baseCheckAll: Boolean
    memberCheckAll: Boolean
    isIndeterminate: Boolean
    isAllIndeterminate: Boolean
    baseAuthorityChecked: Array<any>
    memberChecked: Array<any>
    memberOptions: Array<any>
    beforeCreate(): void {
    }

    initData(that?: any): void {
        that.formData = WLStore().state.memberSet.formData;
        that.formData.splice(0, 0, {})
        that.authority_list = {}
        that.authority_list["item"] = new Array;
        if (WLStore().state.member.type == "set" || WLStore().state.member.type == "edit") {
            that.authority_list["list"] = WLStore().state.memberSet.showData.authority_list
        } else {
            if (isNoEmpty(WLStore().state.memberSet.showData.Authority)) {
                that.authority_list["list"] = WLStore().state.memberSet.showData.Authority
            } else {
                that.authority_list["list"] = []
            }
        }
    }

    mounted(): void {
    }

    editAcc(): void {
        if (WLStore().state.member.type == "set") {
            let sendData = WLStore().state.memberSet.showData
            delete sendData.authority_info_list
            delete sendData.feature_code
            delete sendData.create_time
            delete sendData.update_time
            var arr: Array<any> = [];
            var list = this.formData
            for (let i = 0; i < list.length; i++) {
                if (list[i].child_list) {
                    for (let k = 0; k < list[i].child_list.length; k++) {
                        var index = i.toString() + k.toString()
                        for (let j = 0; j < this.authority_list["item"][index].length; j++) {
                            arr.push(this.authority_list["item"][index][j])
                        }
                    }
                }
            }
            sendData.authority_list = arr

            WLDispatch(MemberConst.DispatchMemberEdit, sendData);
        } else {
            var arr: Array<any> = [];
            var list = this.formData
            for (let i = 0; i < list.length; i++) {
                if (list[i].child_list) {
                    for (let k = 0; k < list[i].child_list.length; k++) {
                        var index = i.toString() + k.toString()
                        for (let j = 0; j < this.authority_list["item"][index].length; j++) {
                            arr.push(this.authority_list["item"][index][j])
                        }
                    }
                }
            }


            var labelArr: Array<any> = [];
            for (let i = 0; i < list.length; i++) {
                if (list[i].child_list) {
                    for (let k = 0; k < list[i].child_list.length; k++) {
                        if (list[i].child_list[k].child_list) {
                            for (let j = 0; j < list[i].child_list[k].child_list.length; j++) {
                                for (let x = 0; x < arr.length; x++) {
                                    if (arr[x] == list[i].child_list[k].child_list[j].id) {
                                        var obj: any = {}
                                        obj["id"] = list[i].child_list[k].child_list[j].id
                                        obj["name"] = list[i].child_list[k].child_list[j].name
                                        labelArr.push(obj)
                                    }
                                }
                            }
                        }
                    }
                }
            }

            if (WLStore().state.member.type == "add") {
                WLCommit(MemberConst.CommitAuthority, labelArr)
            } else if (WLStore().state.member.type == "edit") {
                WLCommit(MemberConst.CommitType, "set")
                let sendData: any = WLStore().state.memberSet.showData
                sendData["authority_info_list"] = labelArr
                sendData["authority_list"] = arr
                WLCommit(MemberConst.CommitMemberShowList, sendData)
            }
        }
    }
}